package reports;

import java.io.IOException;
import java.io.Writer;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class ReportProcessor
 */
@WebServlet("/ReportProcessor")
public class ReportProcessor extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ReportProcessor() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String report = request.getParameter("report"); 
		String startDate = request.getParameter("startDate"); 
		String startMonth = request.getParameter("startMonth"); 
		String startYear = request.getParameter("startYear");
		String endDate = request.getParameter("endDate"); 
		String endMonth = request.getParameter("endMonth"); 
		String endYear = request.getParameter("endYear"); 
		
		Cookie rCookie = new Cookie("report", report);
		Cookie sdCookie = new Cookie("startDate", startDate); 
		Cookie smCookie = new Cookie("startMonth", startMonth);
		Cookie syCookie = new Cookie("startYear", startYear);
		Cookie edCookie = new Cookie("endDate", endDate); 
		Cookie emCookie = new Cookie("endMonth", endMonth);
		Cookie eyCookie = new Cookie("endYear", endYear);
		response.addCookie(rCookie);
		response.addCookie(sdCookie); 
		response.addCookie(smCookie);
		response.addCookie(syCookie);
		response.addCookie(edCookie); 
		response.addCookie(emCookie);
		response.addCookie(eyCookie);
		
		if (report.equals("Sales"))
			response.sendRedirect("sales.jsp"); 
		if (report.equals("Current Inventory"))
			response.sendRedirect("inventory.jsp"); 
		if (report.equals("Inventory"))
			response.sendRedirect("inventory.jsp"); 
		if (report.equals("Best Selling")) 
			response.sendRedirect("best.jsp"); 
		if (report.equals("Worst Selling"))
			response.sendRedirect("worst.jsp"); 
		
		
		
		//Writer w = response.getWriter(); 
		//w.write(report + period + startMonth + startYear + endMonth + endYear); 
	}

}
